$(function () {

    //变量抽取
    var attendance_dataGrid = $("#attendance_dataGrid");
    var attendance_dialog = $("#attendance_dialog");
    var attendance_form = $("#attendance_form");
    attendance_dataGrid.datagrid({
        fitColumns: true,//列自适应
        url: "/attendance/query.do",
        fit: true,
        columns: [[
            {field: 'date', title: '日期', width: 100,align:'center'},
            {field: 'username', title: '员工姓名', width: 100,align:'center'},
            /*{field: 'dept', title: '部门', width: 100,align:'center'},*/
            {field: 'clockIn', title: '上班时间', width: 100, sortable: true,align:'center'},
            {field: 'clockOut', title: '下班时间', width: 100, sortable: true,align:'center'},
            {
                field: 'clockStatus', title: '考勤状态', width: 100,align:'center', formatter: function (value, row, index) {
                    return value ? "<font color='green'>正常</font>" : "<font color='red'>异常</font>";
                }
            }
        ]],
        toolbar: "#tb",//工具
        pagination: true,//分页
        rownumbers: true,//行号
        singleSelect: true,//只允许选择一行


    })
    attendance_dialog.dialog({
        width: 280,
        height: 340,
        buttons: "#btns",
        closed: true,
        onClose: function () {
            attendance_form.form("clear");
        }
    });

    //方法抽成对象统一管理
    var methodObj = {
        searchForm: function () {
            var keyword = $("[name=keyword]").val();
            var beginDate = $("input[name = 'beginDate']").val();
            var endDate = $("input[name = 'endDate']").val();

            attendance_dataGrid.datagrid('load', {
                keyword: keyword,
                beginDate: beginDate,
                endDate : endDate
            });
        },
    }

    //按钮统一绑定事件
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });
})
